<!DOCTYPE HTML>
<html>
<head>
    {include file="common:meta"}
</head>
<body>
<div class="page-container">
    <div class="ibox-content" id="toolbar">
        <form action="" class="form-inline" data-url="">
            <div class="form-group">
                <label class="control-label">
                    <label class="control-label">开始时间：
                        <input type="text" class="form-control date-search" id="start_time" placeholder="yyyyMM">
                    </label>
                </label>
            </div>
            <div class="form-group">
                <label class="control-label">
                    <label class="control-label">结束时间：
                        <input type="text" class="form-control date-search" id="end_time" placeholder="yyyyMM">
                    </label>
                </label>
            </div>

            <div class="form-group">
                <label class="control-label" for="menu_name">菜单名称:</label>
                <input class="form-control" id="menu_name" type="text" name="name">
            </div>
            <button type="button" class="btn btn-primary" id="eventQuery">查询</button>
            <button type="button" onclick="location.replace(location.href);" class="btn btn-success ">刷新</button>
        </form>
    </div>
    <div class="ibox-content">
        <div class="tabs-container">
            <ul class="nav nav-tabs">
                <li class="active"><a data-toggle="tab" href="#tab-1" aria-expanded="true">菜单列表</a></li>
                <li><a data-toggle="tab" href="#tab-2" aria-expanded="false">菜单添加</a></li>
            </ul>
            <div class="tab-content">
                <div class=" tab-pane active" id="tab-1">
                    <table id="tb_departments"></table>
                </div>
                <div class=" tab-pane" id="tab-2">
                    <div class="ibox-content">
                        <form class="form-horizontal" id="form" data-url="/MenuAdd">
                            <div class="form-group">
                                <label class="col-sm-2 control-label"><span class="form-required">*</span>上级</label>
                                <div class="col-md-6 col-sm-10">
                                    <select class="form-control" name="parent_id" id="input-parent_id">
                                        <option value="0">作为一级菜单</option>
                                        {$select_category|raw}
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label"><span class="form-required">*</span>名称</label>
                                <div class="col-md-6 col-sm-10">
                                    <input type="text" class="form-control" id="input-name" name="name">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label"><span class="form-required">*</span>应用</label>
                                <div class="col-md-6 col-sm-10">
                                    <input type="text" class="form-control" id="input-app" name="app">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="input-controller" class="col-sm-2 control-label"><span
                                        class="form-required">*</span>控制器</label>
                                <div class="col-md-6 col-sm-10">
                                    <input type="text" class="form-control" id="input-controller" name="controller">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="input-action" class="col-sm-2 control-label"><span
                                        class="form-required">*</span>方法</label>
                                <div class="col-md-6 col-sm-10">
                                    <input type="text" class="form-control" id="input-action" name="action">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="input-param" class="col-sm-2 control-label">参数</label>
                                <div class="col-md-6 col-sm-10">
                                    <input type="text" class="form-control" id="input-param" name="param">
                                    <p class="help-block">例:id=3&amp;p=3</p>
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="input-param2" class="col-sm-2 control-label">路由</label>
                                <div class="col-md-6 col-sm-10">
                                    <input type="text" class="form-control" id="input-param2" name="route">
                                </div>
                            </div>

                            <div class="form-group">
                                <label for="input-status" class="col-sm-2 control-label">状态</label>
                                <div class="col-md-6 col-sm-10" id="input-status">
                                    <select class="form-control" name="status">
                                        <option value="1">在左侧菜单显示</option>
                                        <option value="0">在左侧菜单隐藏</option>
                                    </select>
                                </div>
                            </div>

                            <div class="form-group">
                                <div class="col-sm-offset-2 col-sm-10">
                                    <button class="btn btn-primary" type="button" onclick="commonSubmit(this)">添加
                                    </button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="common:footer"}
<script>
    $(document).ready(function () {
        initTable();
    });

    function initTable() {
        $('#tb_departments').bootstrapTable({
            url: '/MenuIndexData',         //请求后台的URL（*）
            dataField: "data",
            method: 'post',                      //请求方式（*）
            striped: true,                      //是否显示行间隔色
            cache: true,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
            pagination: true,                   //是否显示分页（*）
            queryParams: queryParams,//传递参数（*）
            showToggle: true,
            showRefresh: true,
            sidePagination: "server",           //分页方式：client客户端分页，server服务端分页（*）
            pageNumber: 1,                       //初始化加载第一页，默认第一页
            pageSize: 25,                       //每页的记录行数（*）
            pageList: [10, 25, 50, 100],        //可供选择的每页的行数（*）
            showColumns: true,                  //是否显示所有的列
            showPaginationSwitch: true,
            minimumCountColumns: 2,             //最少允许的列数
            toolbar: '#toolbar',
            columns: [{
                field: 'list_order',
                title: '排序',
                editable: {
                    type: 'text',
                    title: '排序',
                    validate: function (v) {
                        if (!v) return '排序值不能为空';
                    }
                },
                titleTooltip: '可编辑',
            }, {
                field: 'id',
                title: 'ID',
                sortable: true
            }, {
                field: 'name',
                title: '菜单名称',
            }, {
                field: 'route',
                title: '路由名称',
            }, {
                field: 'Button',
                title: '操作',
                events: operateEvents,
                formatter: operateFormatter
            }],
            //保存的使用
            onEditableSave: function (field, row, oldValue, $el) {
                //可进行异步操作
                $.ajax({
                    type: "post",
                    url: "/MenuEditPost",
                    data: row,
                    dataType: 'JSON',
                    success: function (re) {
                        if (re.code === 1) {
                            layer.msg(re.msg, {icon: 1, time: 2000});
                        } else {
                            layer.alert(re.msg);
                        }
                    },
                    error: function () {
                        alert('编辑失败');
                    },
                    complete: function () {

                    }

                });
            }
        });
    }

    //得到查询的参数

    function queryParams(params) {
        params.offset = params.offset / params.limit + 1;
        params.name = $('#menu_name').val();
        return params;
    }

    function operateFormatter(value, row, index) {
        return [
            '<button type="button"  class="TableEdit btn btn-primary  btn-sm" style="margin-right:15px;">编辑</button>',
            '<button type="button"  class="TableDelete btn btn-primary  btn-sm" style="margin-right:15px;">删除</button>'
        ].join('');
    }

    window.operateEvents = {
        'click .TableEdit': function (e, value, row, index) {
            layopen('MenuEdit', row.id);
        },
        'click .TableDelete': function (e, value, row, index) {
            ajaxDel('MenuDel', row.id, this);
        }
    };
    // 搜索按钮触发事件
    $(function () {
        $("#eventQuery").click(function () {
            $('#tb_departments').bootstrapTable(('refresh'));	// 很重要的一步，刷新url！
        });

    });
    //时间搜索插件
    layui.use('laydate', function () {
        var laydate = layui.laydate;
        lay('.date-search').each(function () {
            laydate.render({
                elem: this,
                type: 'datetime',
                trigger: 'click'
            });
        });
    });
</script>
</body>
</html>